package com.shujia

object Demo16DataSet {
  def main(args: Array[String]): Unit = {

    val array: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8)
    val set1: DataSet = new DataSet(array)

    val set2: DataSet = set1.map(i => i * i)

    println(set2.data.mkString(","))


  }

}

class DataSet(d: Array[Int]) {

  var data: Array[Int] = d


  /**
    * 定义一个方法对data中的数据进行处理
    *
    */

  def map(f: Int => Int): DataSet = {

    var i: Int = 0
    while (i < data.length) {

      data(i) = f(data(i))

      i += 1
    }

    this
  }

}
